package com.jnks.constant.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

/**
 * @author W
 */

@AllArgsConstructor
public enum DeviceTypeEnum {
    PHOTOELECTRIC_REACTION(2,"2", "光电反制一体"),
    OMNIDIRECTIONAL(4,"4", "无线电全向反制"),
    ORIENTATION(5,"5", "无线电定向反制"),
    GPS_DECEIVE(6,"6", "GPS诱骗");

    @Getter
    @Setter
    private Integer intCode;
    @Getter
    @Setter
    private String code;
    @Getter
    @Setter
    private String message;

    public static DeviceTypeEnum getByCode(String code) {
        if (null == code) {
            return null;
        }

        for (DeviceTypeEnum deviceTypeEnum : DeviceTypeEnum.values()) {
            if (deviceTypeEnum.getCode().equals(code)) {
                return deviceTypeEnum;
            }
        }

        return null;
    }

    /**
     * 转化枚举为Map,key为code, value为message
     *
     * @return
     */
    public static Map<String, String> convert2Map() {
        Map<String, String> map = new HashMap<String, String>();
        for (DeviceTypeEnum deviceTypeEnum : DeviceTypeEnum.values()) {
            map.put(deviceTypeEnum.getCode(), deviceTypeEnum.getMessage());
        }
        return map;
    }

}
